﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TheHeGeo.Util;
using TheHeGeoDao;

namespace TheHeGeo.UserControl
{
    public partial class UcJsChartEnglish : System.Web.UI.UserControl
    {
        public string[] SensorName { get; set; }
        public string QueryString { get; set; }
        public int MaDuAn { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            string user = ((SessionUser) (Session[SessionConst.SES_USER])).NguoiSuDung.UserName;
            if (string.IsNullOrEmpty(QueryString)) return;
            var str = QueryString.Split(',');
            var max = str.Length < 20 ? str.Length : 20;
            for (int i = 0; i < max; i++)
            {
                string v = str[i];
                var t = (from d in DaoHelper.Entities.Sensors
                         join b in DaoHelper.Entities.ThietBis on d.MaThietBi equals b.MaThietBi
                         join p in DaoHelper.Entities.PhanQuyenDuAns on b.MaDuAn equals p.MaDuAn
                         where (p.MaDuAn==MaDuAn&&d.MaSensor == v&&p.UserName==user&&b.Status==0) select new{d.MoTa,p.MaDuAn,d.MaSensor}).ToList();
                if (t.Count == 0)
                {
                    return;
                }
                LoadControl(i, t[0].MaSensor);

                string chartTip =  SensorName[i] + " data - " + (string.IsNullOrEmpty(t[0].MoTa) ? "There is no description" : t[0].MoTa);
                ScriptManager.RegisterStartupScript(Page, GetType(), i + "",
                    "<script type='text/javascript'>abc('#" + i + "','r=" + str[i] + "','" + chartTip+ "',"+"'&d="+t[0].MaDuAn+"')</script>", false);

            }
            
        }

        protected void LoadControl(int i,string maSensor)
        {
            UcGrlTestData uc = null;
           
            switch (i)
            {
                case 0:uc = UcGrlTestData_0;break;
                case 1: uc = UcGrlTestData_1; break;
                case 2: uc = UcGrlTestData_2; break;
                case 3: uc = UcGrlTestData_3; break;
                case 4: uc = UcGrlTestData_4; break;
                case 5: uc = UcGrlTestData_5; break;
                case 6: uc = UcGrlTestData_6; break;
                case 7: uc = UcGrlTestData_7; break;
                case 8: uc = UcGrlTestData_8; break;
                case 9: uc = UcGrlTestData_9; break;
                case 10: uc = UcGrlTestData_10; break;
                case 11: uc = UcGrlTestData_11; break;
                case 12: uc = UcGrlTestData_12; break;
                case 13: uc = UcGrlTestData_13; break;
                case 14: uc = UcGrlTestData_14; break;
                case 15: uc = UcGrlTestData_15; break;
                case 16: uc = UcGrlTestData_16; break;
                case 17: uc = UcGrlTestData_17; break;
                case 18: uc = UcGrlTestData_18; break;
                case 19: uc = UcGrlTestData_19; break;
            }

            if (uc != null)
            {
                uc.Visible = true;
                uc.MaSensor = maSensor;
                uc.LoadTestData();
            }
        }

    }
}